import { createDom, createTitle } from '../utils'
import {
  systemMac,
  systemAndroid,
  systemWindows,
  systemH5,
  getKernel,
  webAppEnvironment,
  setLocalStorage,
  getLocalStorage,
  removeLocalStorage,
  clearLocalStorage,
  setSessionStorage,
  getSessionStorage,
  removeSessionStorage,
  clearSessionStorage,
} from '../../lib/index'

// 标题
createTitle('系统')

// Mac
;(function () {
  const p = createDom('p', ['是否是Mac系统'], {}, false)
  createDom('div', [p], { class: 'item' })
  const status = systemMac()
  console.log(status, 'systemMac')
})()

// Android
;(function () {
  const p = createDom('p', ['是否是Android系统'], {}, false)
  createDom('div', [p], { class: 'item' })
  const status = systemAndroid()
  console.log(status, 'systemAndroid')
})()

// Window
;(function () {
  const p = createDom('p', ['是否是Window系统'], {}, false)
  createDom('div', [p], { class: 'item' })
  const status = systemWindows()
  console.log(status, 'systemWindows')
})()

// h5端
;(function () {
  const p = createDom('p', ['是否是h5端'], {}, false)
  createDom('div', [p], { class: 'item' })
  const status = systemH5()
  console.log(status, 'systemH5')
})()

// 浏览器内核
;(function () {
  const p = createDom('p', ['浏览器内核'], {}, false)
  createDom('div', [p], { class: 'item' })
  const browser = getKernel()
  console.log(browser, 'getKernel')
})()

// H5页面打开的APP类型
;(function () {
  const p = createDom('p', ['H5页面打开的APP类型'], {}, false)
  createDom('div', [p], { class: 'item' })
  const appType = webAppEnvironment()
  console.log(appType, 'webAppEnvironment')
})()

// localStorage
;(function () {
  const p = createDom('p', ['操作localStorage'], {}, false)
  const add = createDom('button', ['设置'], {}, false)
  const gets = createDom('button', ['获取'], {}, false)
  const remove = createDom('button', ['删除'], {}, false)
  const clear = createDom('button', ['清空'], {}, false)
  createDom('div', [p, add, gets, remove, clear], { class: 'item' })
  add.onclick = () => {
    setLocalStorage('add', { name: 'testName', age: 1 })
  }
  gets.onclick = () => {
    const names = getLocalStorage('add')
    console.log(names, 'getLocalStorage')
  }
  remove.onclick = () => {
    removeLocalStorage('add')
  }
  clear.onclick = () => {
    clearLocalStorage()
  }
})()

// sessionStorage
;(function () {
  const p = createDom('p', ['操作sessionStorage'], {}, false)
  const add = createDom('button', ['设置'], {}, false)
  const gets = createDom('button', ['获取'], {}, false)
  const remove = createDom('button', ['删除'], {}, false)
  const clear = createDom('button', ['清空'], {}, false)
  createDom('div', [p, add, gets, remove, clear], { class: 'item' })
  add.onclick = () => {
    setSessionStorage('add', { name: 'testName', age: 1, list: [1, 2, 3, 4, { arr: ['a', 'b'] }] })
  }
  gets.onclick = () => {
    const names = getSessionStorage('add')
    console.log(names, 'getLocalStorage')
  }
  remove.onclick = () => {
    removeSessionStorage('add')
  }
  clear.onclick = () => {
    clearSessionStorage()
  }
})()